package api

import (
	"fmt"
	"io"
	"os"
	"net/http"
	"strconv"
	"time"

	"github.com/labstack/echo"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
	"github.com/mia0x75/mac/models"
	"github.com/mia0x75/mac/core"
)

var pool *core.Pool

func createRelation(c echo.Context) error {
	return c.NoContent(http.StatusNoContent)
}

func getRelation(c echo.Context) error {
	return c.NoContent(http.StatusNoContent)
}

func updateRelation(c echo.Context) error {
	return c.NoContent(http.StatusNoContent)
}

func deleteRelation(c echo.Context) error {
	id, _ := strconv.ParseUint(c.Param("id"), 10, 32)
	relation := &models.Relation{
		RelationId: id,
	}

	conn, err := pool.Get()

	if err != nil {
		return c.HTML(500, err.Error())
	}

	if db, ok := conn.(*gorm.DB); ok {
		db.Delete(&relation)
		return c.HTML(200, fmt.Sprintf("%v", relation))
	} else {
		return c.NoContent(http.StatusNoContent)
	}
}

